package user

import (
	"gin-base/base/config"
	"gin-base/base/db"
	"github.com/jinzhu/gorm"
)

type User struct {
	UnionId string `gorm:"size:255"` // Default size for string is 255, reset it with this tag
	gorm.Model
}

func (User) TableName() string {
	return config.Ini.String("mysql.table_prefix") + "user"
}

func GetUserByUnionId(unionId string) User {
	db := db.Open()
	defer db.Close()

	user := []User{}

	db.Where("union_id = ?", unionId).First(&user)

	var userOne User
	if len(user) != 0 {
		userOne = user[0]
	}

	return userOne
}
